﻿
using Direct.IDAL;
using Direct.IDAL.Manager;
using Direct.IDAL.Manager.Admin;
using Direct.IDAL.Manager.Money;
using Direct.IDAL.Manager.Notice;
using Direct.IDAL.Manager.ServiceCenter;
using Direct.IDAL.Manager.UserCenter;
using Direct.IDAL.Message;
using Direct.IDAL.ServiceCenterApply;
using Direct.IDAL.User.Bonus;
using Direct.IDAL.User.Jurisdiction;
using Direct.IDAL.User.Money;
using DirectSell.BLL.Manager.Login;
using DirectSell.BLL.Manager.Money;
using DirectSell.BLL.Manager.ServiceCenter;
using DirectSell.BLL.User.Jurisdiction;
using DirectSell.BLL.User.Money;
using DirectSell.BLL.User.ServiceCenterApply;
using DirectSell.DAL;
using DirectSell.DAL.Manager;
using DirectSell.DAL.Manager.Admin;
using DirectSell.DAL.Manager.MessageManage;
using DirectSell.DAL.Manager.Notice;
using DirectSell.DAL.Manager.ServiceCenter;
using DirectSell.DAL.Manager.UserCenter;
using DirectSell.DAL.User;
using DirectSell.DAL.User.Bonus;
using DirectSell.DAL.User.Jurisdiction;
using DirectSell.DAL.User.Message;
using DirectSell.DAL.User.Money;
using DirectSell.DAL.User.ServiceCenterApply;
using DirectSell.IBLL;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using System.Web.Http;
using System.Web.Mvc;
using Unity.WebApi;
namespace DirectSell.Core
{
   public  class UnityConfig
    {
        public static void Register()
        {
            var container = new UnityContainer();
            container.AddNewExtension<Interception>();

            #region 前台用户

            #region 账户管理注入
            //注入数据访问层 会员注册
            container.RegisterType<IRegisterRepository, RegisterRepository>(new ContainerControlledLifetimeManager())
               .Configure<Interception>().SetInterceptorFor<IRegisterRepository>(new InterfaceInterceptor());
            //注入业务层 会员注册
            container.RegisterType<IOperation,RegisterService>("UserReigster",new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 会员登录
            container.RegisterType<ILoginRepository, LoginRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<ILoginRepository>(new InterfaceInterceptor());
            //注入业务层 会员登录
            container.RegisterType<IOperation,LoginService>("UserLogin", new ContainerControlledLifetimeManager())
              .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 会员修改资料
            container.RegisterType<IModifyInfoRespository, ModifyInfoRespositoty>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IModifyInfoRespository>(new InterfaceInterceptor());
            //注入业务层 会员修改资料
            container.RegisterType<IOperation, ModifyInfoService>("UserModify",new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 会员修改密码
            container.RegisterType<IModifyPasswordRepository, ModifyPasswordRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IModifyPasswordRepository>(new InterfaceInterceptor());
            //注入业务逻辑从 会员修改密码
            container.RegisterType<IOperation, ModifyPasswordSevice>("UserModifyPassword", new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 会员激活
            container.RegisterType<IActivationRepository, ActivationRepository>( new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IActivationRepository>(new InterfaceInterceptor());
            //注入业务逻辑层 会员激活
            container.RegisterType<IOperation, ActivationService>("UserActivation",new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());

            //注入数据访问层 网络图
            container.RegisterType<INetworkMapRepository, NetworkMapRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<INetworkMapRepository>(new InterfaceInterceptor());
            //推荐关系图
            container.RegisterType<IRefreeMapRepository, RefreeMapRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IRefreeMapRepository>(new InterfaceInterceptor());

            //前台 公告
            container.RegisterType<IUserNoticeRepository, UserNoticeRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IUserNoticeRepository>(new InterfaceInterceptor());
            //留言
            container.RegisterType<IMessageRepository, MessageRepository>(new ContainerControlledLifetimeManager())
         .Configure<Interception>().SetInterceptorFor<IMessageRepository>(new InterfaceInterceptor());
            //留言(Mongodb)
            container.RegisterType<IMongoDAL.User.IMessageRepository,MongoDAL.User.Message.MessageRepository>(new ContainerControlledLifetimeManager())
         .Configure<Interception>().SetInterceptorFor<IMongoDAL.User.IMessageRepository>(new InterfaceInterceptor());


            #endregion

            #region 财务管理
            //注入数据访问层 电子币申请
            container.RegisterType<IVirtualMoneyRepository, VirtualMoneyRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IVirtualMoneyRepository>(new InterfaceInterceptor());
            //注入业务逻辑层 电子币申请
            container.RegisterType<IOperation, VirtualMoneyService>("VirtualMoney", new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 申请提现
            container.RegisterType<IRealMoneyRepository, RealMoneyRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IRealMoneyRepository>(new InterfaceInterceptor());
            //注入业务逻辑层 申请提现
            container.RegisterType<IOperation, RealMoneyService>("RealMoney", new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 货币转换
            container.RegisterType<IMoneyTransforRepository, MoneyTransforRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IMoneyTransforRepository>(new InterfaceInterceptor());
            //注入业务层 货币转换
            container.RegisterType<IOperation, MoneyTransforService>("MoneyTransfor",new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 内部转账
            container.RegisterType<IUserGiroRepository, UserGiroRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IUserGiroRepository>(new InterfaceInterceptor());
            //注入业务层 内部转账
            container.RegisterType<IOperation, UserGiroService>("UserGiro",new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            //注入数据访问层 收支查询
            container.RegisterType<IEarningRepository, EarningRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IEarningRepository>(new InterfaceInterceptor());
            #endregion

            #region 奖金管理
            container.RegisterType<IBonusRepository, BonusRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IBonusRepository>(new InterfaceInterceptor());
            #endregion

            #region 服务中心操作注入
            //注入数据访问层 服务中心操作
            container.RegisterType<IServiceCenterRepository, ServiceCenterRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IServiceCenterRepository>(new InterfaceInterceptor());
            //注入业务逻辑层 服务中心操作
            container.RegisterType<IOperation, ServiceCenterService>("ServiceCenter", new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());

            //用户升级仓储层注入
            container.RegisterType<IUserUpgradeRepository, UserUpgradeRepository>( new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IUserUpgradeRepository>(new InterfaceInterceptor());
            //用户升级业务层注入
            container.RegisterType<IOperation, UserUpgradeService>("UserUpGrade", new ContainerControlledLifetimeManager())
          .Configure<Interception>().SetInterceptorFor<IOperation>(new InterfaceInterceptor());
            #endregion

            #endregion

            #region 后台管理
            //注入数据访问层  后台管理基类
            container.RegisterType<IBaseManagerRepository, BaseManagerRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IBaseManagerRepository>(new InterfaceInterceptor());
            //注入数据访问层  后台登录
            container.RegisterType<IManagerLoginRepository, ManagerLoginRepository>(new ContainerControlledLifetimeManager())
             .Configure<Interception>().SetInterceptorFor<IManagerLoginRepository>(new InterfaceInterceptor());
            //注入服务层  后台登录
            container.RegisterType<IManagerOperation, ManagerLoginService>("ManagerLogin",new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IManagerOperation>(new InterfaceInterceptor());
            //注入数据访问层 已开通用户
            container.RegisterType<IMemberListRepository, MemberListRepository>( new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IMemberListRepository>(new InterfaceInterceptor());
            //注入后台位置网络图
            container.RegisterType<IBackNetworkmapRepository, BackNetworkmapRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IBackNetworkmapRepository>(new InterfaceInterceptor());
            //注入会员升级审核
            container.RegisterType<IUpgradeAuditRepository, UpgradeAuditRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IUpgradeAuditRepository>(new InterfaceInterceptor());
            //注入会员升级审核服务层
            container.RegisterType<IManagerOperation, UpgradeAuditService>("ManagerUpgrade", new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IManagerOperation>(new InterfaceInterceptor());
            //注入会员推荐结构图
            container.RegisterType<IBackRefreeMapRepository, BackRefreeMapRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IBackRefreeMapRepository>(new InterfaceInterceptor());
            //注入电子币审核
            container.RegisterType<IVirtualMoneyAuditRepository, VirtualMoneyAuditRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IVirtualMoneyAuditRepository>(new InterfaceInterceptor());
             //注入电子币审核服务层
            container.RegisterType<IManagerOperation, VirtualMoneyAuditService>("ManagerVirtualMoney",new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IManagerOperation>(new InterfaceInterceptor());
            //注入提现审核仓储层
            container.RegisterType<IRealMoneyAuditRepository, RealMoneyAuditRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IRealMoneyAuditRepository>(new InterfaceInterceptor());
            //注入提现审核服务层
            container.RegisterType<IManagerOperation, RealMoneyAuditService>("ManagerRealMoney", new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<IManagerOperation>(new InterfaceInterceptor());
            //注入服务中心审核仓储层
            container.RegisterType<IServiceCenterAuditRepository, ServiceCenterAuditRepository>(new ContainerControlledLifetimeManager())
          .Configure<Interception>().SetInterceptorFor<IServiceCenterAuditRepository>(new InterfaceInterceptor());
            //注入服务中心审核服务层
            container.RegisterType<IManagerOperation, SerciceCenterAuditService>("ManagerServiceAudit",new ContainerControlledLifetimeManager())
          .Configure<Interception>().SetInterceptorFor<IManagerOperation>(new InterfaceInterceptor());
            //注入发布公告数据访问层
            container.RegisterType<INoticeManagerRepository, NoticeManagerRepository>(new ContainerControlledLifetimeManager())
            .Configure<Interception>().SetInterceptorFor<INoticeManagerRepository>(new InterfaceInterceptor());
            //注入管理员管理数据访问层
            container.RegisterType<IAdminRepository, AdminRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IAdminRepository>(new InterfaceInterceptor());
            //注入留言管理数据访问层
            container.RegisterType<IMessageManageRepository, MessageManageRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IMessageManageRepository>(new InterfaceInterceptor());
            //注入留言管理数据访问层(Mongodb)
            container.RegisterType<IMongoDAL.Manager.MessageManage.IMessageManageRepository, MongoDAL.Manager.MessageManage.MessageManageRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IMongoDAL.Manager.MessageManage.IMessageManageRepository>(new InterfaceInterceptor());

            //全部数据清空
            container.RegisterType<IDelMsgRepository, DelMsgRepository>(new ContainerControlledLifetimeManager())
           .Configure<Interception>().SetInterceptorFor<IDelMsgRepository>(new InterfaceInterceptor());

            #endregion

            DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);

        }
    }
}
